<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/static/img/logo/favicon.ico" />
    <link rel="stylesheet" href="/static/assets/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/css/footer.css">
    <link rel="stylesheet" href="/static/css/header.css">
    <title>论坛</title>

</head>

<body class="home">
    {% include 'header.html' %}

    <div style="width: 100%;height: 60%;">
        <div style="width: 300px; height: 100px; margin: 0 auto;margin-top: 15%;margin-bottom: 20%;">
            <div class="span4">
                <div class="input-prepend" style="width: 300px;">
                    <span class="add-on">更改账号：</span><input style="width: 200px" class="span2" id="uid" size="16"
                        type="text" name="old_pwd" disabled="disabled" placeholder="{{ uid }}">
                </div>
                <div class="input-prepend" style="width: 300px;">
                    <span class="add-on">原始密码：</span><input style="width: 200px" class="span2" id="oldpwd" size="16"
                        type="password" name="old_pwd" placeholder="原密码">
                </div>
                <div class="input-prepend">
                    <span class="add-on">新的密码：</span><input style="width: 200px" class="span2" id="pwd" size="16"
                        type="password" name="new_pwd1" placeholder="新密码">
                </div>
                <div class="input-prepend">
                    <span class="add-on">确认密码：</span><input style="width: 200px" class="span2" id="pwd2" size="16"
                        type="password" name="new_pwd2" placeholder="确认密码">
                </div>
                <div style="width: 300px;padding: 20px;margin: 0 auto;">
                    <button id="login-button " style="margin-right: 20px;margin-left: 20px;" class="btn btn-secondary"
                        type="submit">提交
                    </button>
                    <button id="cancel-button" style="margin-right: 20px;margin-left: 20px;"
                        class="btn btn-secondary btn-inverse" type="submit">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    {% include 'footer.html' %}

    <script src="/static/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/static/assets/plugins/jquery/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#login-button').click(function () {
                var old_pwd = $('#oldpwd').val();
                var pwd1 = $('#pwd').val();
                var pwd2 = $('#pwd2').val();
                $.ajax({
                    url: window.location.href,
                    type: "POST",
                    data: { 'old_pwd': old_pwd, 'new_pwd1': pwd1, 'new_pwd2': pwd2 },
                    beforeSend: function (xhr, settings) {
                        xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    
                    },
                    success: function (data) {
                        if (!data.status) alert(data.msg);
                        else window.location.href = "/login/";
                    }
                });
            });

            $('#cancel-button').click(function () {
                window.location.href = "/home";
            });
        });
    </script>
</body>

</html>